<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name:'级别'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
            <ul style="color:#333">
                <li  v-for="(item,index) in gradeLog" :key="index" class="lh28">{{item.logcontent}}</li>
            </ul>
    </div>
    <div class="layerRtb-footer">
       <div class="analyItem">
            <p class="analyItemTit tx-center">手动调级</p>
            <div class="analyItemCon pb5">
                <div class="col-md-6 borderight h_percent100">
                    <div class="clearfix">
                        <p class="fl">当前<span class="cGreen fz15 peopleNowLevel">{{level}}</span>级</p>
                        <p class="fl ml10">调至
                            <select id="changelevel" class="curL-sel" v-model="upGradelevel">
                                <option value="20">20</option>
                                <option value="21">21</option>
                                </select>
                            级
                            <input type="text" class="form-control hide width60" v-model="content" id="addtime">
                        </p>
                    </div>
                    <div class="mt5 clearfix">
                        <div class="col-md-7">
                            <textarea rows="2" class="pa5" style="width:100%;" id="changeremark" v-model="content"></textarea>
                            <p class="tx-center mt5">
                                <input type="button" class="uiBtn-blue uiBtn-small" value="提交" style="width:60px;" id="changebutton"  @click="upGradeHistory()">
                            </p>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 h_percent100 pl5 pa5">
                    <p class="cBlue">记录</p>
                    <div class="slimScrollDiv" style="position: relative; overflow: hidden; width: auto; height: 250px;"><div class="pmuser_level_changehistoryl" style="overflow: hidden; width: auto; height: 101px;">
                        <div class="recordScroll_new" id="pmuser_level_changehistory" style="position:absolute; height:100px; overflow:auto"><div class="pl10 pr10 fl " style="width: 100%;" ng-repeat="li in scaleRecord"><p>【手动设置级别为 {{this.upHistory.level}}】{{this.upHistory.content}} </p><span class="fr pb5" style="border-bottom: 1px dashed;width: 100%;text-align: right;">{{this.upHistory.creat_user}}          {{this.upHistory.creat_time}}</span></div></div>
                    </div><div class="slimScrollBar" style="background: rgb(206, 206, 206); width: 2px; position: absolute; top: 101px; opacity: 0.4; display: none; border-radius: 0px; z-index: 99; right: 1px;"></div><div class="slimScrollRail" style="width: 2px; height: 100%; position: absolute; top: 0px; display: none; border-radius: 7px; background: rgb(51, 51, 51); opacity: 0.2; z-index: 90; right: 1px;"></div></div>
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
// eslint-disable-next-line standard/object-curly-even-spacing
import { getUserLevelDetail, upGrageReson, findUserLevelHistory, findUpGradeLog} from '../../Resources/Api/index'

export default {
    data () {
        return {
            level: {},
            content: '',
            upGradelevel: '20',
            upHistory: {},
            gradeLog: []
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo'])
    },
    created () {
        this.userCurrentLevel()
        this.UserLevelHistory()
        this.UpGradeLog()
    },
    methods: {
        ...mapMutations({
            setLeftData: `SET_LEFT_INFO`,
            setUpdatePlate: `SET_UPDATE_PLATE`
        }),
        UpGradeLog () {
            findUpGradeLog({
                uid: this.leftInfo.uid
            }).then(result => {
                this.gradeLog = result.data.Body
            }).catch(err => {
                console.log(err)
            })
        },
        upGradeHistory () {
            upGrageReson({
                uid: this.leftInfo.uid,
                content: this.content,
                upGradelevel: this.upGradelevel,
                objectType: 2,
                dataType: 1,
                creatNo: this.userInfo.userNo,
                creatUser: this.userInfo.as_fullName,
                createuserno: this.userInfo.userNo,
                createuserman: this.userInfo.as_fullName,
                orderno: this.leftInfo.uid,
                logcontent: '【手动设置级别从' + this.level + '调整至' + this.upGradelevel + '级】' + this.content + ' ' + this.userInfo.as_fullName + '' + this.formatter(new Date(), 'yyyy-MM-dd hh:mm:ss'),
                importance: 100001,
                logtype: 123456
            }).then(result => {
                this.upHistory.level = this.upGradelevel
                this.upHistory.content = this.content
                this.upHistory.creat_user = this.userInfo.userName
                this.upHistory.creat_time = this.formatter(new Date(), 'yyyy-MM-dd hh:mm:ss')
                this.setLeftData()
                this.setUpdatePlate()
                this.UserLevelHistory()
                this.content = ''
                this.$router.push(`/projectFiles/Person/personnelPersonnelDetail3`)
            }).catch(err => {
                console.log(err)
            })
        },
        userCurrentLevel () {
            getUserLevelDetail({
                uid: this.leftInfo.uid
            }).then(result => {
                this.level = result.data.Body
            })
        },
        formatter (thistime, fmt) {
            let $this = new Date(thistime)
            let o = {
                'M+': $this.getMonth() + 1,
                'd+': $this.getDate(),
                'h+': $this.getHours(),
                'm+': $this.getMinutes(),
                's+': $this.getSeconds(),
                'q+': Math.floor(($this.getMonth() + 3) / 3),
                'S': $this.getMilliseconds()
            }
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ($this.getFullYear() + '').substr(4 - RegExp.$1.length))
            }
            for (var k in o) {
                if (new RegExp('(' + k + ')').test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
                }
            }
            return fmt
        },
        UserLevelHistory () {
            findUserLevelHistory({
                uid: this.leftInfo.uid
            }).then(result => {
                this.upHistory = result.data.Body
            }).catch(err => {
                console.log(err)
            })
        }
    },
    watch: {
        leftInfo () {
            this.userCurrentLevel()
        }
    }
}
</script>
